//
//  MSPasswordCell.m
//  MOSS
//
//  Created by apple on 2019/1/12.
//  Copyright © 2019年 apple. All rights reserved.
//

#import "MSPasswordCell.h"

@interface MSPasswordCell ()

@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UIButton *secretBtn;
@end

@implementation MSPasswordCell

+ (instancetype)createTableView:(UITableView *)tableView {
    MSPasswordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"passwordCell"];
    cell.selectionStyle  = UITableViewCellSelectionStyleNone;

    [cell makeViews];
    
    return cell;
}


- (void)makeViews {
    
    [self.contentView addSubview:self.textField];
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(45);
        make.top.mas_equalTo(25);
        make.right.mas_equalTo(-75);
        make.height.mas_equalTo(30);
    }];
    
    [self.contentView addSubview:self.secretBtn];
    UIImage *img = [UIImage imageNamed:@"yanjing_bi"];
    
    [self.secretBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(35);
        make.right.mas_equalTo(-45);
        make.width.mas_equalTo(img.size.width);
        make.height.mas_equalTo(img.size.height);
    }];
    
    UIView *lineView = [[UIView alloc]init];
    [self.contentView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(40);
        make.right.equalTo(-40);
        make.top.equalTo(59.5);
        make.height.equalTo(0.5);
    }];
    lineView.backgroundColor = tTableViewCellLine;
    
}

- (void)secretClick {
    
    _textField.secureTextEntry = !_textField.secureTextEntry;
    if (_textField.secureTextEntry)  {
        [_secretBtn setImage:[UIImage imageNamed:@"yanjing_bi"] forState:UIControlStateNormal];
    }
    else {
        [_secretBtn setImage:[UIImage imageNamed:@"yanjing"] forState:UIControlStateNormal];
    }
}

- (UIButton *)secretBtn {
    if (!_secretBtn) {
        _secretBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_secretBtn setImage:[UIImage imageNamed:@"yanjing_bi"] forState:UIControlStateNormal];
        [_secretBtn addTarget:self action:@selector(secretClick) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _secretBtn;
}

- (UITextField *)textField {
    if (!_textField) {
        _textField = [[UITextField alloc] init];
        _textField.placeholder = LocalizationKey(@"Enter a password combining 8-20 digits and letters");
//        [_textField setValue:[UIColor colorWithHEX:@"F6F6F6"] forKeyPath:@"_placeholderLabel.textColor"];
        _textField.textColor = tThreeColor;
        _textField.font = [UIFont systemFontOfSize:14];
        _textField.secureTextEntry = YES;
        _textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    }
    
    return _textField;
}


@end
